package org.sbbs.admin.manager.impl;

import jakarta.annotation.PostConstruct;
import org.sbbs.admin.dao.SysAreaRepo;
import org.sbbs.admin.entity.SysArea;
import org.sbbs.admin.manager.SysAreaManager;
import org.sbbs.base.jpa.manager.impl.BaseTreeCacheManagerImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 *
 * @author jenkins
 */
@Service
@Qualifier("sysAreaManager")
public class SysAreaManagerImpl extends BaseTreeCacheManagerImpl<SysArea, Long, SysAreaRepo> implements SysAreaManager {

    @Autowired
    private SysAreaRepo repo;

    @PostConstruct
    public void init() {
        super.setRepo(repo);
        this.setCache(this.getCacheManager().getCache("sysAreaCache"));
        this.getCache().clear();
//        this.getCache().
        this.load(true);
    }

//    @Autowired
//    private SysAreaRepo repo;
//
//    @PostConstruct
//    public void init() {
//        super.setRepo(repo);
//    }
//
//    @Override
//    public List<SysArea> findChildren(SysArea pid) {
//        List<SysArea> sa = repo.findByPidOrderBySort(pid.getId());
//
//        for (SysArea sysArea : sa) {
//            sysArea.setParent(pid);
//        }
//        return sa;
//    }
//
//    @Override
//    public Boolean hasChildren(SysArea p) {
////        SysArea p1 = new SysArea();
////        p1.setId(p.getId());
////        
//        SysArea e = new SysArea();
//        e.setPid(p.getId());
//        Example<SysArea> em = Example.of(e);
//        return repo.exists(em);
//    }
//
//    @Override
//    public void updateChildrenSort(List<SysArea> children) {
//        for (int i = 0; i < children.size(); i++) {
//            SysArea get = children.get(i);
//            get.setSort(i);
//        }
//
//        this.repo.saveAllAndFlush(children);
//    }
}
